<?php class leeproOptions {
	function getOptions(){
		$options = get_option('leepro_option');
		if(!is_array($options)){
			
			$options['show_feature_post'] 		= '1';	// show_feature_post
			$options['show_about_us_ad'] = '1';
			$options['show_post_welcome'] = '1'; 			// url:image logo theme
			$options['show_info_site']	= '';		
			$options['show_top_video']	= '';
			$options['show_form_contact'] = '';
			$options['show_sidebar_new_tab1'] = '';//show_sidebar_new_tab1
			$options['show_sidebar_new_tab2'] = '';//show_sidebar_new_tab2
			$options['show_sidebar_new_tab3'] = '';//show_sidebar_new_tab2
			$options['show_Breaking_new'] = '';//show_Breaking_new
			$options['show_about_us'] = '';//show_about_us
			$options['show_footer_address'] = '';//show_footer_address
			$options['show_site_map'] = '';
			$options['show_info_contact']	= '';		// Info contact
			$options['show_most_popular']	= '1';//show_most_popular
			$options['slution_about_us']	= '';
			$options['leepro_link_footer']	= '';
			$options['analytics'] 			= false;
			$options['analytics_content'] 	= '';
			$options['google_cse'] 			= false;
			$options['google_cse_cx'] 		= '';
			$options['nosidebar'] 			= false;
			$options['google_cse'] = false;
			$options['google_cse_cx'] = '';
			$options['menu_type'] = 'pages';
			$options['nosidebar'] = false;
			$options['notice'] = false;
			$options['notice_content'] = '';
			$options['banner_registered'] = false;
			$options['banner_commentator'] = false;
			$options['banner_visitor'] = false;
			$options['banner_content'] = '';
			$options['showcase_registered'] = false;
			$options['showcase_commentator'] = false;
			$options['showcase_visitor'] = false;
			$options['showcase_caption'] = false;
			$options['showcase_title'] = '';
			$options['showcase_content'] = '';
			$options['author'] = true;
			$options['categories'] = true;
			$options['tags'] = true;
			$options['ctrlentry'] = false;
			$options['feed_readers'] = true;
			$options['feed'] = false;
			$options['feed_url'] = '';
			$options['feed_email'] = false;
			$options['feed_url_email'] = '';
			$options['twitter'] = false;
			$options['twitter_username'] = '';
			$options['analytics'] = false;
			$options['analytics_content'] = '';
			
			// Link to more website
			update_option('leepro_option',$options);
			
		}
		return $options;

	}
	// <dic id=""/>    </>
	// /^<(.*)\n\r\t\d\D\s\S\w\W>$/
	function leepro_content_to_excerpt($num) {
	$theContent = get_the_content();
	$output = preg_replace('/<img[^>]+./','', $theContent);
	$output = preg_replace( '/<blockquote>.*<\/blockquote>/', '', $output );
	$output = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $output );
	$limit = $num+1;
	$content = explode(' ', $output, $limit);
	array_pop($content);
	$content = implode(" ",$content)."...";
	return $content;
	}
function lee_pro_limit_content($set_content,$limit) {
  $content = explode(' ', $set_content, $limit);
  if (count($content)>=$limit) {
    array_pop($content);
    $content = implode(" ",$content).'...';
  } else {
    $content = implode(" ",$content);
  }	
  $array_replate = '/<[^>]+./';//             '/<[^>]+./'
  $content = preg_replace($array_replate, '', $content);
  return $content;
}

function the_content_rss($more_link_text='...', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
	_deprecated_function( __FUNCTION__, '2.9', 'the_content_feed' );
	$content = get_the_content($more_link_text, $stripteaser, $more_file);
	$content = apply_filters('the_content_rss', $content);
	if ( $cut && !$encode_html )
		$encode_html = 2;
	if ( 1== $encode_html ) {
		$content = esc_html($content);
		$cut = 0;
	} elseif ( 0 == $encode_html ) {
		$content = make_url_footnote($content);
	} elseif ( 2 == $encode_html ) {
		$content = strip_tags($content);
	}
	if ( $cut ) {
		$blah = explode(' ', $content);
		if ( count($blah) > $cut ) {
			$k = $cut;
			$use_dotdotdot = 1;
		} else {
			$k = count($blah);
			$use_dotdotdot = 0;
		}

		/** @todo Check performance, might be faster to use array slice instead. */
		for ( $i=0; $i<$k; $i++ )
			$excerpt .= $blah[$i].' ';
		$excerpt .= ($use_dotdotdot) ? '...' : '';
		$content = $excerpt;
	}
	$content = str_replace(']]>', ']]&gt;', $content);
	return $content;
}

function leePro_get_the_excerpt($post_id) {
  global $post;  
  $save_post = $post;
  $post = get_post($post_id);
  $output = get_the_excerpt($post_id);
  $post = $save_post;
  return $output;
}
function leePro_trim_excerpt( $content ,$lenght) {
    if($lenght == null)
		$lenght = 200;
	$return = substr( 0, $lenght, strip_tags( $content ) );
	var_dump($return);
	return $return;
}
function get_excerpt_outside_loop($post_id){
global $wpdb;
$query = 'SELECT post_excerpt FROM '. $wpdb->posts .' WHERE ID = '. $post_id .' LIMIT 1';
$result = $wpdb->get_results($query, ARRAY_A);
$post_excerpt=$result[0]['post_excerpt'];
return $post_excerpt;
}	
//length option
function the_title_max_charlength_option($charlength,$set_title ='',$type = 'tiltle') {
	   if($set_title=='')
			$title_ = trim(get_the_title());
		else
			$title_ = $set_title;
	   $charlength++;
	   if(strlen($title_)>$charlength) {
			if($type == 'title')
				$subex = substr($title_,0,$charlength);
			else
				$subex = substr($title_,0,$charlength-5);
		   $exwords = explode(" ",$subex);
		   $excut = -(strlen($exwords[count($exwords)-1]));
		   if($excut<0) {
				echo substr($subex,0,$excut);
		   } else {
				echo $subex;
		   }
		   echo "...";
	   } else {
		   echo $title_;
	   }
	}
	
	function echo_the_title(){
			return  trim(get_the_title());
	}
	function x_the_title_max_charlength($charlength,$set_title ='',$type = 'tiltle') {
	   if($set_title=='')
			$title_ = trim(get_the_title());
		else
			$title_ = $set_title;
	   $charlength++;
	   if(strlen($title_)>$charlength) {
			if($type == 'title')
				$subex = substr($title_,0,$charlength);
			else
				$subex = substr($title_,0,$charlength-5);
		   $exwords = explode(" ",$subex);
		   $excut = -(strlen($exwords[count($exwords)-1]));
		   if($excut<0) {
				return substr($subex,0,$excut)."...";
		   } else {
				echo $subex."...";
		   }
	   } else {
		   return $title_;
	   }
	}
//length 
	function the_excerpt_max_charlength($charlength) {
	   $excerpt = trim(get_the_excerpt());
	   $charlength++;
	   if(strlen($excerpt)>$charlength) {
		
		   $subex = substr($excerpt,0,$charlength-5);
		   $exwords = explode(" ",$subex);
		   $excut = -(strlen($exwords[count($exwords)-1]));
		   if($excut<0) {
				echo substr($subex,0,$excut);
		   } else {
				echo $subex;
		   }
		   echo "...";
	   } else {
		   echo $excerpt;
	   }
	}
	function echo_the_excerpt_max_charlength($charlength = null) {
	   $excerpt = trim(get_the_excerpt());
	   if($charlength !=null ){
	   $charlength++;
	   $set_the_excerpt ='';
	   if(strlen($excerpt)>$charlength) {
		
		   $subex = substr($excerpt,0,$charlength-5);
		   $exwords = explode(" ",$subex);
		   $excut = -(strlen($exwords[count($exwords)-1]));
		   if($excut<0) {
				$set_the_excerpt .= substr($subex,0,$excut);
		   } else {
				$set_the_excerpt .= $subex;
		   }
		   $set_the_excerpt .= "...";
		   return $set_the_excerpt;
	   }} else {
		   return $excerpt;
	   }
	}
	function the_title_max_charlength($charlength) {
	   $title_ = trim(get_the_title());
	   $charlength++;
	   if(strlen($title_)>$charlength) {
		
		   $subex = substr($title_,0,$charlength);
		   $exwords = explode(" ",$subex);
		   $excut = -(strlen($exwords[count($exwords)-1]));
		   if($excut<0) {
				echo substr($subex,0,$excut);
		   } else {
				echo $subex;
		   }
		   echo "...";
	   } else {
		   echo $title_;
	   }
	}
	
	function leePro_get_link_excerpt($lenght =null){
		if(empty($lenght))
			$lenght = 100;
		$LinkExcerpt = strip_tags(substr(get_the_excerpt(), 0, $lenght ));
		if($LinkExcerpt != '')
		{
			return $LinkExcerpt."...";
		}
		return '';
    }

	function leeProget_excerpt_outside_loop($post_id){
		global $wpdb;
		$query = "SELECT post_excerpt FROM ". $wpdb->posts ." WHERE ID = ". $post_id ." LIMIT 1";
		$result = $wpdb->get_results($query, ARRAY_A);
		$post_excerpt=$result[0]['post_excerpt'];
		return $post_excerpt;
		}

/**
 * Retrieve or display list of pages in list (li) format.
 *
 * @since 1.5.0
 *
 * @param array|string $args Optional. Override default arguments.
 * @return string HTML content, if not displaying.
 */
function leepro_wp_list_pages($args = '') {
	$defaults = array(
		'depth' => 0, 'show_date' => '',
		'date_format' => get_option('date_format'),
		'child_of' => 0, 'exclude' => '',
		'title_li' => __('Pages'), 'echo' => 1,
		'authors' => '', 'sort_column' => 'menu_order, post_title',
		'link_before' => '', 'link_after' => '', 'walker' => '',
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	$output = '';
	$current_page = 0;

	// sanitize, mostly to keep spaces out
	$r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);

	// Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
	$exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array();
	$r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) );

	// Query pages.
	$r['hierarchical'] = 0;
	$pages = get_pages($r);

	if ( !empty($pages) ) {
		if ( $r['title_li'] )
			$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';

		global $wp_query;
		if ( is_page() || is_attachment() || $wp_query->is_posts_page )
			$current_page = $wp_query->get_queried_object_id();
		$output .= $this->leepro_walk_page_tree($pages, $r['depth'], $current_page, $r);

		if ( $r['title_li'] )
			$output .= '</ul></li>';
	}

	$output = apply_filters('wp_list_pages', $output, $r);

	if ( $r['echo'] )
		echo $output;
	else
		return $output;
}

/**
 * Retrieve HTML list content for page list.
 *
 * @uses Walker_Page to create HTML list content.
 * @since 2.1.0
 * @see Walker_Page::walk() for parameters and return description.
 */
function leepro_walk_page_tree($pages, $depth, $current_page, $r) {
	if ( empty($r['walker']) )
			$walker = new leepro_Walker_Page;
		else
			$walker = $r['walker'];

		$args = array($pages, $depth, $r, $current_page);
		return call_user_func_array(array(&$walker, 'walk'), $args);
}

	
/**
 * Display or retrieve the HTML list of categories.
 *
 * The list of arguments is below:
 *     'show_option_all' (string) - Text to display for showing all categories.
 *     'orderby' (string) default is 'ID' - What column to use for ordering the
 * categories.
 *     'order' (string) default is 'ASC' - What direction to order categories.
 *     'show_last_update' (bool|int) default is 0 - See {@link
 * walk_category_dropdown_tree()}
 *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
 * in the category.
 *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
 * don't have any posts attached to them.
 *     'use_desc_for_title' (bool|int) default is 1 - Whether to use the
 * description instead of the category title.
 *     'feed' - See {@link get_categories()}.
 *     'feed_type' - See {@link get_categories()}.
 *     'feed_image' - See {@link get_categories()}.
 *     'child_of' (int) default is 0 - See {@link get_categories()}.
 *     'exclude' (string) - See {@link get_categories()}.
 *     'exclude_tree' (string) - See {@link get_categories()}.
 *     'echo' (bool|int) default is 1 - Whether to display or retrieve content.
 *     'current_category' (int) - See {@link get_categories()}.
 *     'hierarchical' (bool) - See {@link get_categories()}.
 *     'title_li' (string) - See {@link get_categories()}.
 *     'depth' (int) - The max depth.
 *
 * @since 2.1.0
 *
 * @param string|array $args Optional. Override default arguments.
 * @return string HTML content only if 'echo' argument is 0.
 */
function leepro_wp_list_categories( $args = '' ) {
	$defaults = array(
		'show_option_all' => '', 'show_option_none' => __('No categories'),
		'orderby' => 'name', 'order' => 'ASC',
		'show_last_update' => 0, 'style' => 'list',
		'show_count' => 0, 'hide_empty' => 1,
		'use_desc_for_title' => 1, 'child_of' => 0,
		'feed' => '', 'feed_type' => '',
		'feed_image' => '', 'exclude' => '',
		'exclude_tree' => '', 'current_category' => 0,
		'hierarchical' => true, 'title_li' => __( 'Categories' ),
		'echo' => 1, 'depth' => 0,
		'taxonomy' => 'category'
	);

	$r = wp_parse_args( $args, $defaults );

	if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] )
		$r['pad_counts'] = true;

	if ( isset( $r['show_date'] ) )
		$r['include_last_update_time'] = $r['show_date'];

	if ( true == $r['hierarchical'] ) {
		$r['exclude_tree'] = $r['exclude'];
		$r['exclude'] = '';
	}

	if ( !isset( $r['class'] ) )
		$r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];

	extract( $r );

	if ( !taxonomy_exists($taxonomy) )
		return false;

	$categories = get_categories( $r );

	$output = '';
	if ( $title_li && 'list' == $style )
			$output = '<li class="' . esc_attr( $class ) . ' ">' . $title_li . '<ul>';

	if ( empty( $categories ) ) {
		if ( ! empty( $show_option_none ) ) {
			if ( 'list' == $style )
				$output .= '<li>' . $show_option_none . '</li>';
			else
				$output .= $show_option_none;
		}
	} else {
		if( !empty( $show_option_all ) )
			if ( 'list' == $style )
				$output .= '<li><a href="' .  get_bloginfo( 'url' )  . '">' . $show_option_all . '</a></li>';
			else
				$output .= '<a href="' .  get_bloginfo( 'url' )  . '">' . $show_option_all . '</a>';

		if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {
			$current_term_object = get_queried_object();
			if ( $r['taxonomy'] == $current_term_object->taxonomy )
				$r['current_category'] = get_queried_object_id();
		}

		if ( $hierarchical )
			$depth = $r['depth'];
		else
			$depth = -1; // Flat.

		$output .= $this->leepro_walk_category_tree( $categories, $depth, $r );
	}

	if ( $title_li && 'list' == $style )
		$output .= '</ul></li>';

	$output = apply_filters( 'wp_list_categories', $output, $args );

	if ( $echo )
		echo $output;
	else
		return $output;
}

	//
// Helper functions
//

/**
 * Retrieve HTML list content for category list.
 *
 * @uses Walker_Category to create HTML list content.
 * @since 2.1.0
 * @see Walker_Category::walk() for parameters and return description.
 */
function leepro_walk_category_tree() {
	$args = func_get_args();
	// the user's options are the third parameter
	if ( empty($args[2]['walker']) || !is_a($args[2]['walker'], 'Walker') )
		$walker = new leepro_Walker_Category;
	else
		$walker = $args[2]['walker'];

	return call_user_func_array(array( &$walker, 'walk' ), $args );
}

	function leepro_get_post($postID) {
		global $entry;

		if ( !current_user_can( 'edit_post', $postID ) )
			//$this->auth_required( __( 'Sorry, you do not have the right to access this post.' ) );
			return  null;
		$this->set_current_entry($postID);
		$output = $this->get_entry($postID);
		return $output;
		//log_app('function',"get_post($postID)");
		//$this->output($output);

	}
	
	function add() {
		if(isset($_POST['leepro_save'])) {
			$options = leeproOptions::getOptions();

			// Url slide background
			$options_save['show_feature_post'] = stripslashes($_POST['show_feature_post']);
			
			//Show About Us
			$options_save['show_about_us_ad'] = stripslashes($_POST['show_about_us_ad']);

			// Url image of logo

			$options_save['show_post_welcome'] = stripslashes($_POST['show_post_welcome']);
			
			//Info show_info_site

			$options_save['show_info_site'] = stripslashes($_POST['show_info_site']);
			//show_top_video
			$options_save['show_top_video'] = stripslashes($_POST['show_top_video']);
			//show_sidebar_new_tab1
			$options_save['show_sidebar_new_tab1'] = stripslashes($_POST['show_sidebar_new_tab1']);
			
			//show_sidebar_new_tab2
			$options_save['show_sidebar_new_tab2'] = stripslashes($_POST['show_sidebar_new_tab2']);
			
			//show_sidebar_new_tab3
			$options_save['show_sidebar_new_tab3'] = stripslashes($_POST['show_sidebar_new_tab3']);

			//show_footer_address
			if ($_POST['show_footer_address']) {
				$options_save['show_footer_address'] = (bool)true;
			} else {
				$options_save['show_footer_address'] = (bool)false;
			}
			$options_save['show_footer_address'] = stripslashes($_POST['show_footer_address']);
			
			$options_save['show_about_us'] = stripslashes($_POST['show_about_us']);
			
			//$options['show_form_contact']
			$options_save['show_form_contact'] = stripslashes($_POST['show_form_contact']);
			
			//$options['show_site_map']
			$options_save['show_site_map'] = stripslashes($_POST['show_site_map']);
			
			//show_most_popular
			$options_save['show_most_popular'] = stripslashes($_POST['show_most_popular']);
			
			//slution_about_us
			$options_save['slution_about_us'] = stripslashes($_POST['slution_about_us']);
			
			//
			$options_save['show_info_contact'] = stripslashes($_POST['show_info_contact']);
			
			
			//Reccent photo
			$options_save['show_event_travel'] = stripslashes($_POST['show_event_travel']);
			
			// google custom search engine
			$options_save['google_cse_cx'] = stripslashes($_POST['google_cse_cx']);

			// menu

			
			// sidebar
			if ($_POST['nosidebar']) {
				$options_save['nosidebar'] = (bool)true;
			} else {
				$options_save['nosidebar'] = (bool)false;
			}
			$options_save['nosidebar'] = stripslashes($_POST['nosidebar']);
		// google custom search engine
			if ($_POST['google_cse']) {
				$options_save['google_cse'] = (bool)true;
			} else {
				$options_save['google_cse'] = (bool)false;
			}
			$options_save['google_cse_cx'] = stripslashes($_POST['google_cse_cx']);
			
			//$options['show_top_content'] = 'top';//show_top_content
			$options_save['show_top_content'] = stripslashes($_POST['show_top_content']);
			
			// menu
			$options_save['menu_type'] = stripslashes($_POST['menu_type']);

			// sidebar
			if ($_POST['nosidebar']) {
				$options_save['nosidebar'] = (bool)true;
			} else {
				$options_save['nosidebar'] = (bool)false;
			}

			// notice
			if ($_POST['notice']) {
				$options_save['notice'] = (bool)true;
			} else {
				$options_save['notice'] = (bool)false;
			}
			$options_save['notice_content'] = stripslashes($_POST['notice_content']);

			// banner
			if (!$_POST['banner_registered']) {
				$options_save['banner_registered'] = (bool)false;
			} else {
				$options_save['banner_registered'] = (bool)true;
			}
			if (!$_POST['banner_commentator']) {
				$options_save['banner_commentator'] = (bool)false;
			} else {
				$options_save['banner_commentator'] = (bool)true;
			}
			if (!$_POST['banner_visitor']) {
				$options_save['banner_visitor'] = (bool)false;
			} else {
				$options_save['banner_visitor'] = (bool)true;
			}
			$options_save['banner_content'] = stripslashes($_POST['banner_content']);

			// showcase
			if (!$_POST['showcase_registered']) {
				$options_save['showcase_registered'] = (bool)false;
			} else {
				$options_save['showcase_registered'] = (bool)true;
			}
			if (!$_POST['showcase_commentator']) {
				$options_save['showcase_commentator'] = (bool)false;
			} else {
				$options_save['showcase_commentator'] = (bool)true;
			}
			if (!$_POST['showcase_visitor']) {
				$options_save['showcase_visitor'] = (bool)false;
			} else {
				$options_save['showcase_visitor'] = (bool)true;
			}
			if ($_POST['showcase_caption']) {
				$options_save['showcase_caption'] = (bool)true;
			} else {
				$options_save['showcase_caption'] = (bool)false;
			}
			$options_save['showcase_title'] = stripslashes($_POST['showcase_title']);
			$options_save['showcase_content'] = stripslashes($_POST['showcase_content']);

			// posts
			if ($_POST['author']) {
				$options_save['author'] = (bool)true;
			} else {
				$options_save['author'] = (bool)false;
			}
			if ($_POST['categories']) {
				$options_save['categories'] = (bool)true;
			} else {
				$options_save['categories'] = (bool)false;
			}
			if (!$_POST['tags']) {
				$options_save['tags'] = (bool)false;
			} else {
				$options_save['tags'] = (bool)true;
			}

			// ctrl + entry
			if ($_POST['ctrlentry']) {
				$options_save['ctrlentry'] = (bool)true;
			} else {
				$options_save['ctrlentry'] = (bool)false;
			}

			// feed
			if (!$_POST['feed_readers']) {
				$options_save['feed_readers'] = (bool)false;
			} else {
				$options_save['feed_readers'] = (bool)true;
			}
			if ($_POST['feed']) {
				$options_save['feed'] = (bool)true;
			} else {
				$options_save['feed'] = (bool)false;
			}
			$options_save['feed_url'] = stripslashes($_POST['feed_url']);
			if ($_POST['feed_email']) {
				$options_save['feed_email'] = (bool)true;
			} else {
				$options_save['feed_email'] = (bool)false;
			}
			$options_save['feed_url_email'] = stripslashes($_POST['feed_url_email']);

			// twitter
			if ($_POST['twitter']) {
				$options_save['twitter'] = (bool)true;
			} else {
				$options_save['twitter'] = (bool)false;
			}
			$options_save['twitter_username'] = stripslashes($_POST['twitter_username']);

			// analytics
			if ($_POST['analytics']) {
				$options_save['analytics'] = (bool)true;
			} else {
				$options_save['analytics'] = (bool)false;
			}
			$options_save['analytics_content'] = stripslashes($_POST['analytics_content']);

		
			$message_save = '';
			if ($options != $options_save) {
					if(!update_option("leepro_option",$options_save)) {
						$message_save = __("Updated Failed",'leepro_youdivvy');
					}else{
						$message_save = __("Updated",'leepro_youdivvy');
						//$options= get_option("leepro_option");
					}
			}
		}
		else {
			leeproOptions::getOptions();
		}

		add_theme_page(__('YouDivvy Theme Option', 'leepro_youdivvy'), __('YouDivvy Theme Option', 'leepro_youdivvy'), 'edit_themes', basename(__FILE__), array('leeproOptions', 'display'));
	}
	
	function display() {
		$options = leeproOptions::getOptions();
			if(is_admin()){
			?>
			
			<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/lib/css/admin-tabs.css" type="text/css" />
			<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/lib/js/jquery-1.5.1.min.js"></script>
			<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/lib/js/jquery.ui.core.js"></script>
			<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/lib/js/jquery.ui.widget.js"></script>
			<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/lib/js/jquery.ui.tabs.js"></script>
			
			<?php };?>
			<script>
	$(function() {
		$( "#tabs" ).tabs();
	});
	</script>
	<form action="#" method="post" enctype="multipart/form-data" name="leepro_form" id="leepro_form">
		<div class="wrap">
			<div class="icon32" id="icon-options-general"><br></div>
			<h2><?php _e('Youdivvy Theme Options', 'leepro_youdivvy'); ?></h2>
			<div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
					<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
						<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#show_post_option">Show post to index</a></li>												
						<li class="ui-state-default ui-corner-top"><a href="#headway-system-info-tab">System Info</a></li>	
									
					</ul>
			
				<!-- Start show_post_option -->
				<div class="tab ui-tabs-panel ui-widget-content ui-corner-bottom" id="show_post_option">
					<h2>Show post to index</h2>
					
					<table width="100%">
						<tr>
						
							<td width="25%" valign="top">
								Note: When you the option to display information on the homepage. See instructions on next image to the exact option.
								<hr/><h4> Contact and Site map</h4>
								<table class="form-table">
									<tbody>
										<tr valign="top">
											<th scope="row">
												<?php _e('Show form contact(*1)', 'leepro_youdivvy'); ?>
												<br/>
												<small style="font-weight:normal;"><?php _e('Id page', 'leepro_youdivvy'); ?></small>
											</th>
											<td>
												<label>
													<input type="text" name="show_form_contact" id="show_form_contact" class="code" size="10" value="<?php echo($options['show_form_contact']); ?>">
												</label>
											</td>
										</tr>
									</tbody>
								</table>
								
								<table class="form-table">
									<tbody>
										<tr valign="top">
											<th scope="row">
												<?php _e('Show site map(*2)', 'leepro_youdivvy'); ?>
												<br/>
												<small style="font-weight:normal;"><?php _e('Id page', 'leepro_youdivvy'); ?></small>
											</th>
											<td>
												<label>
													<input type="text" name="show_site_map" id="show_site_map" class="code" size="10" value="<?php echo($options['show_site_map']); ?>">
												</label>
											</td>
										</tr>
									</tbody>
							</table>
								<hr/><h4> Show Content</h4>
								<table class="form-table">
									<tbody>
										<tr valign="top">
											<th scope="row">
												<?php _e('Show feature post(*3)', 'leepro_youdivvy'); ?>
												<br/>
												<small style="font-weight:normal;"><?php _e('Choose category', 'leepro_youdivvy'); ?></small>
												
									
												<label>
													
													<?php wp_dropdown_categories(array('hide_empty' => 1, 'show_count'=> 1, 'selected' => $options['show_feature_post'],'hide_if_empty' => true, 'taxonomy' => 'category', 'name' => 'show_feature_post', 'orderby' => 'name', 'hierarchical' => true)); ?>
												</label>
											</th>
										</tr>
										<tr valign="top">
											<th scope="row">
												<?php _e('Show Top Videos', 'leepro_youdivvy'); ?>
												<br/>
												<small style="font-weight:normal;"><?php _e('Choose category', 'leepro_youdivvy'); ?></small>
												
									
												<label>
													
													<?php wp_dropdown_categories(array('hide_empty' => 1, 'show_count'=> 1, 'selected' => $options['show_top_video'],'hide_if_empty' => true, 'taxonomy' => 'category', 'name' => 'show_top_video', 'orderby' => 'name', 'hierarchical' => true)); ?>
												</label>
											</th>
										</tr>
										<tr valign="top">
											<th scope="row">
												<?php _e('Show Tab 1', 'leepro_youdivvy'); ?>
												<br/>
												<small style="font-weight:normal;"><?php _e('Choose category', 'leepro_youdivvy'); ?></small> 
												
									
												<label>
													
													<?php wp_dropdown_categories(array('hide_empty' => 1, 'show_count'=> 1, 'selected' => $options['show_sidebar_new_tab1'],'hide_if_empty' => true, 'taxonomy' => 'category', 'name' => 'show_sidebar_new_tab1', 'orderby' => 'name', 'hierarchical' => true)); ?>
												</label>
											</th>
										</tr>
										<tr valign="top">
											<th scope="row">
												<?php _e('Show Tab 2', 'leepro_youdivvy'); ?>
												<br/>
												<small style="font-weight:normal;"><?php _e('Choose category', 'leepro_youdivvy'); ?></small> 
												
									
												<label>
													
													<?php wp_dropdown_categories(array('hide_empty' => 1, 'show_count'=> 1, 'selected' => $options['show_sidebar_new_tab2'],'hide_if_empty' => true, 'taxonomy' => 'category', 'name' => 'show_sidebar_new_tab2', 'orderby' => 'name', 'hierarchical' => true)); ?>
												</label>
											</th>
										</tr>
										<tr valign="top">
											<th scope="row">
												<?php _e('Show Tab 3', 'leepro_youdivvy'); ?>
												<br/>
												<small style="font-weight:normal;"><?php _e('Choose category', 'leepro_youdivvy'); ?></small> 
												
									
												<label>
													
													<?php wp_dropdown_categories(array('hide_empty' => 1, 'show_count'=> 1, 'selected' => $options['show_sidebar_new_tab3'],'hide_if_empty' => true, 'taxonomy' => 'category', 'name' => 'show_sidebar_new_tab3', 'orderby' => 'name', 'hierarchical' => true)); ?>
												</label>
											</th>
										</tr>
									</tbody>
								</table>
								
								<hr/><h4>Show Menubar(*17)</h4>
								<table class="form-table">
									<tbody>
										<tr valign="top">
											<td>
												<label style="margin-right:20px;">
													<input name="menu_type" type="radio" value="pages" <?php if($options['menu_type'] != 'categories') echo "checked='checked'"; ?> />
													 <?php _e('Show pages as menu.', 'leepro_youdivvy'); ?>
												</label>
											</td>
										</tr>
									</tbody>
								</table>
								<table class="form-table">
									<tbody>
										<tr valign="top">
											<td>
												<label>
													<input name="menu_type" type="radio" value="categories" <?php if($options['menu_type'] == 'categories') echo "checked='checked'"; ?> />
													 <?php _e('Show categories as menu.', 'leepro_youdivvy'); ?>
												</label>
											</td>
										</tr>
									</tbody>
								</table>
						</td>
							<td class="td_option_travel" width="75%" valign="top" vertical-align="top">
								<img class="set_img_option_travel" src="<?php bloginfo('template_directory')?>/screenshot.png" width="600px" height="389px"/>
								
							</td>
						</tr>
					</table>
																
					<hr/><h4> Option Auth </h4>
									
					<table class="form-table">
						<tbody>
							<tr valign="top">
								<th scope="row"><?php _e('Posts', 'leepro_youdivvy'); ?></th>
								<td>
									<label style="margin-right:20px;">
										<input name="author" type="checkbox" value="checkbox" <?php if($options['author']) echo "checked='checked'"; ?> />
										 <?php _e('Show author on posts.', 'leepro_youdivvy'); ?>
									</label>
									<label style="margin-right:20px;">
										<input name="categories" type="checkbox" value="checkbox" <?php if($options['categories']) echo "checked='checked'"; ?> />
										 <?php _e('Show categories on posts.', 'leepro_youdivvy'); ?>
									</label>
									<label>
										<input name="tags" type="checkbox" value="checkbox" <?php if($options['tags']) echo "checked='checked'"; ?> />
										 <?php _e('Show tags on posts.', 'leepro_youdivvy'); ?>
									</label>
								</td>
							</tr>
						</tbody>
					</table>

					

					
					<hr/><h4>Show Footer</h4>

					<table class="form-table">
						<tbody>
							<tr valign="top">
								<th scope="row">
									<?php _e('Footer Address(*12)', 'leepro_youdivvy'); ?>
									<br/>
									<small style="font-weight:normal;"><?php _e('Input Address', 'leepro_youdivvy'); ?></small>
								</th>
								<td>
									<label>
										<textarea name="show_footer_address" cols="50" rows="2" id="show_footer_address" class="code" style="width:98%;font-size:12px;"><?php echo($options['show_footer_address']); ?></textarea>
									</label>
								</td>
							</tr>
						</tbody>
					</table>
		
				</div>
				<!-- End show_post_option -->

				<!-- Start System Info Panel -->
				<div class="tab ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="headway-system-info-tab">
					<h2>System Info</h2>

					<h3 class="border-top">WordPress Version <span><?php global $wp_version; echo $wp_version; ?></span></h3>
						
										
						<h3 class="border-top">PHP Version<span><?php echo PHP_VERSION; ?></span></h3>
						
						
						<?php if(function_exists('mysql_get_server_info')){ ?>
						<h3 class="border-top">MySQL Version<span><?php echo mysql_get_server_info(); ?></span></h3>
						
						<?php } ?>
						
						<h3 class="border-top">Web Server Info<span><?php echo $_SERVER['SERVER_SOFTWARE']; ?></span></h3>
						
						
						<h3 class="border-top">Browser Info<span><?php echo $_SERVER['HTTP_USER_AGENT']; ?></span></h3>
						

						<h3 class="border-top">PHP cURL Support<span><?php echo (function_exists('curl_init')) ? 'Yes' : 'No'; ?></span></h3>
						
						
						<h3 class="border-top">PHP GD (Image Library) Support<span><?php echo (function_exists('gd_info')) ? 'Yes' : 'No'; ?></span></h3>
						
				</div>
				<!-- End System Info Panel -->
						
					
			</div>
			<p class="submit">
			<input class="button-primary" type="submit" name="leepro_save" value="<?php _e('Save Changes', 'leepro_youdivvy'); ?>" />
			</p>
		</div>

	</form>	
	<?php }
	
}
add_action('admin_menu', array('leeproOptions', 'add'));

/** l10n */
function theme_init(){
	load_theme_textdomain('diginet', get_template_directory() . '/languages');
}
add_action ('init', 'theme_init');
function new_excerpt_length($length = null) {
		return 30;
}
add_filter('excerpt_length', 'new_excerpt_length');
// Changing excerpt more
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

 if(function_exists('register_sidebar')){
		register_sidebar(array(
		'name' => 'main_sidebar_footer',
		'before_widget' => '<div class="moduletable-services %1$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3>',
		'after_title' => '</h3>'
	));
	register_sidebar(array(
		'name' => 'left_sidebar',
		'before_widget'=>'<div class="module-full"><div class="widget widget_gantry_pages rt-block" id="gantry_pages-%1$s"><div class="module-surround"><div class="module-tm"><div class="module-l"><div class="module-r"><div class="module-bm"><div class="module-tl"><div class="module-tr"><div class="module-bl"><div class="module-br"><div class="module-title"><div class="module-title2"><div class="module-title3">',
		'after_widget' => '</div></div></div></div></div></div></div></div></div></div></div></div>',
		'before_title' => '<h2 class="title" style="visibility: visible;">',
		'after_title' => '</h2></div></div></div><div class="module-content module_content_widget">'
	));
}

/** Comments */
if (function_exists('wp_list_comments')) {
	// comment count
	function comment_count( $commentcount ) {
		global $id;
		$_comments = get_comments('status=approve&post_id=' . $id);
		$comments_by_type = &separate_comments($_comments);
		return count($comments_by_type['comment']);
	}
}

// custom comments
function custom_comments($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment;
	global $commentcount;
	if(!$commentcount) {
		$commentcount = 0;
	}
?>
	<li class="comment <?php if($comment->comment_author_email == get_the_author_email()) {echo 'admincomment';} else {echo 'regularcomment';} ?>" id="comment-<?php comment_ID() ?>">
		<div class="author">
			<div class="pic">
				<?php if (function_exists('get_avatar') && get_option('show_avatars')) { echo get_avatar($comment, 32); } ?>
			</div>
			<div class="name">
				<?php if (get_comment_author_url()) : ?>
					<a id="commentauthor-<?php comment_ID() ?>" class="url" href="<?php comment_author_url() ?>" rel="external nofollow">
				<?php else : ?>
					<span id="commentauthor-<?php comment_ID() ?>">
				<?php endif; ?>

				<?php comment_author(); ?>

				<?php if(get_comment_author_url()) : ?>
					</a>
				<?php else : ?>
					</span>
				<?php endif; ?>
			</div>
		</div>

		<div class="info">
			<div class="date">
				<?php printf( __('%1$s at %2$s', 'leepro_youdivvy'), get_comment_time(__('M d, Y', 'leepro_youdivvy')), get_comment_time(__('H:i', 'leepro_youdivvy')) ); ?>
					 | <a href="#comment-<?php comment_ID() ?>"><?php printf('#%1$s', ++$commentcount); ?></a>
			</div>
			<div class="act">
				<a href="javascript:void(0);" onclick="MGJS_CMT.reply('commentauthor-<?php comment_ID() ?>', 'comment-<?php comment_ID() ?>', 'comment');"><?php _e('Reply', 'leepro_youdivvy'); ?></a> | 
				<a href="javascript:void(0);" onclick="MGJS_CMT.quote('commentauthor-<?php comment_ID() ?>', 'comment-<?php comment_ID() ?>', 'commentbody-<?php comment_ID() ?>', 'comment');"><?php _e('Quote', 'leepro_youdivvy'); ?></a>
				<?php
					if (function_exists("qc_comment_edit_link")) {
						qc_comment_edit_link('', ' | ', '', __('Edit', 'leepro_youdivvy'));
					}
					edit_comment_link(__('Advanced edit', 'leepro_youdivvy'), ' | ', '');
				?>
			</div>
			<div class="fixed"></div>
			<div class="content">
				<?php if ($comment->comment_approved == '0') : ?>
					<p><small><?php _e('Your comment is awaiting moderation.', 'leepro_option'); ?></small></p>
				<?php endif; ?>

				<div id="commentbody-<?php comment_ID() ?>">
					<?php comment_text(); ?>
				</div>
			</div>
		</div>
		<div class="fixed"></div>


<?php 
}
/*
*	Solution_LeePro
**/
//include('lib/widget/Solution_LeePro.php');
/*
*	01 - Main Event DaoTien Restaurant
**/
//include('lib/widget/leepro_main_event_widget.php');

/*
*	01 - Show Block Bottom 
**/
//include('lib/widget/LeePro_Show_Block_Bottom.php');

/* 
 * Adsend Dell 
 * */
//include('lib/widget/LeePro_Adsense_dell.php');
/* 
 * Tạo Leepro_Who_online widget 
 * */
include('lib/widget/LeePro_Who_online.php');
/* 
 * Yahoo_Status
 * */
include('lib/widget/Yahoo_Status.php');

/* 
 * Slide Show
 * */
//include('lib/widget/LeePro_slideShow.php');
//Add thumnai with post
//add_theme_support('post-thumbnails', array('post'));
//Add thumnai with page
//add_theme_support('post-thumbnails', array('page'));
/** arena_softech options */
add_theme_support('post-thumbnails');

add_action('publish_page', 'add_custom_field_automatically');
add_action('publish_post', 'add_custom_field_automatically');
function add_custom_field_automatically($post_ID) {
	global $wpdb;
	if(!wp_is_post_revision($post_ID)) {
		add_post_meta($post_ID, 'field-name', 'custom value', true);
	}
}
/**
 * Create HTML list of pages.
 *
 * @package WordPress
 * @since 2.1.0
 * @uses Walker
 */

/**
 * Create HTML list of pages.
 *
 * @package WordPress
 * @since 2.1.0
 * @uses Walker
 */
class leepro_Walker_Page extends Walker {
	/**
	 * @see Walker::$tree_type
	 * @since 2.1.0
	 * @var string
	 */
	var $tree_type = 'page';

	/**
	 * @see Walker::$db_fields
	 * @since 2.1.0
	 * @todo Decouple this.
	 * @var array
	 */
	var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');

	/**
	 * @see Walker::start_lvl()
	 * @since 2.1.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param int $depth Depth of page. Used for padding.
	 */
	function start_lvl(&$output, $depth) {
		$indent = str_repeat("\t", $depth);
		$output .= "\n$indent<ul class='level2 child_level_nav'>\n";
	}

	/**
	 * @see Walker::end_lvl()
	 * @since 2.1.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param int $depth Depth of page. Used for padding.
	 */
	function end_lvl(&$output, $depth) {
		$indent = str_repeat("\t", $depth);
		$output .= "$indent</ul>\n";
	}

	/**
	 * @see Walker::start_el()
	 * @since 2.1.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param object $page Page data object.
	 * @param int $depth Depth of page. Used for padding.
	 * @param int $current_page Page ID.
	 * @param array $args
	 */
	function start_el(&$output, $page, $depth, $args, $current_page) {
		if ( $depth )
			$indent = str_repeat("\t", $depth);
		else
			$indent = '';

		extract($args, EXTR_SKIP);
		$css_class = array('parent root f-main-parent', 'page-item-'.$page->ID);
		if ( !empty($current_page) ) {
			$_current_page = get_page( $current_page );
			_get_post_ancestors($_current_page);
			if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) )
				$css_class[] = 'current_page_ancestor';
			if ( $page->ID == $current_page )
				$css_class[] = 'current_page_item';
			elseif ( $_current_page && $page->ID == $_current_page->post_parent )
				$css_class[] = 'current_page_parent';
		} elseif ( $page->ID == get_option('page_for_posts') ) {
			$css_class[] = 'current_page_parent';
		}

		$css_class = implode(' ', apply_filters('page_css_class', $css_class, $page));
		$a_class ='orphan item bullet bullet';
		$output .= $indent . '<li class="' . $css_class . '"><a class="'.$a_class.'" href="' . get_permalink($page->ID) . '" title="' . esc_attr( wp_strip_all_tags( apply_filters( 'the_title', $page->post_title, $page->ID ) ) ) . '"><span>' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</span></a>';

		if ( !empty($show_date) ) {
			if ( 'modified' == $show_date )
				$time = $page->post_modified;
			else
				$time = $page->post_date;

			$output .= " " . mysql2date($date_format, $time);
		}
	}

	/**
	 * @see Walker::end_el()
	 * @since 2.1.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param object $page Page data object. Not used.
	 * @param int $depth Depth of page. Not Used.
	 */
	function end_el(&$output, $page, $depth) {
		$output .= "</li>\n";
	}

}

/**
 * Create HTML list of categories.
 *
 * @package WordPress
 * @since 2.1.0
 * @uses Walker
 */
class leepro_Walker_Category extends Walker {
	/**
	 * @see Walker::$tree_type
	 * @since 2.1.0
	 * @var string
	 */
	var $tree_type = 'category';

	/**
	 * @see Walker::$db_fields
	 * @since 2.1.0
	 * @todo Decouple this
	 * @var array
	 */
	var $db_fields = array ('parent' => 'parent', 'id' => 'term_id');

	/**
	 * @see Walker::start_lvl()
	 * @since 2.1.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param int $depth Depth of category. Used for tab indentation.
	 * @param array $args Will only append content if style argument value is 'list'.
	 */
	function start_lvl(&$output, $depth, $args) {
		if ( 'list' != $args['style'] )
			return;

		$indent = str_repeat("\t", $depth);
		$output .= $indent.'<ul class="level2 child_level_nav">';
	}

	/**
	 * @see Walker::end_lvl()
	 * @since 2.1.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param int $depth Depth of category. Used for tab indentation.
	 * @param array $args Will only append content if style argument value is 'list'.
	 */
	function end_lvl(&$output, $depth, $args) {
		if ( 'list' != $args['style'] )
			return;

		$indent = str_repeat("\t", $depth);
		$output .= "$indent</ul>";
	}

	/**
	 * @see Walker::start_el()
	 * @since 2.1.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param object $category Category data object.
	 * @param int $depth Depth of category in reference to parents.
	 * @param array $args
	 */
	function start_el(&$output, $category, $depth, $args) {
		extract($args);

		$cat_name = esc_attr( $category->name );
		$cat_name = apply_filters( 'list_cats', $cat_name, $category );
		$a_class ='orphan item bullet bullet';
		$link = '<a class="'.$a_class.'" href="' . esc_attr( get_term_link($category) ) . '" ';
		if ( $use_desc_for_title == 0 || empty($category->description) )
			$link .= 'title="' . esc_attr( sprintf(__( 'View all posts filed under %s' ), $cat_name) ) . '"';
		else
			$link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"';
		$link .= '><span>';
		$link .= $cat_name . '</span></a>';

		if ( !empty($feed_image) || !empty($feed) ) {
			$link .= ' ';

			if ( empty($feed_image) )
				$link .= '(';

			$link .= '<a class="'.$a_class.'" href="' . get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) . '"';

			if ( empty($feed) ) {
				$alt = ' alt="' . sprintf(__( 'Feed for all posts filed under %s' ), $cat_name ) . '"';
			} else {
				$title = ' title="' . $feed . '"';
				$alt = ' alt="' . $feed . '"';
				$name = $feed;
				$link .= $title;
			}

			$link .= '>';

			if ( empty($feed_image) )
				$link .= $name;
			else
				$link .= "<img src='$feed_image'$alt$title" . ' /><span>';

			$link .= '</span></a>';

			if ( empty($feed_image) )
				$link .= ')';
		}

		if ( !empty($show_count) )
			$link .= ' (' . intval($category->count) . ')';

		if ( !empty($show_date) )
			$link .= ' ' . gmdate('Y-m-d', $category->last_update_timestamp);

		if ( 'list' == $args['style'] ) {
			$output .= "\t<li";
			$class = 'cat-item-' . $category->term_id.' parent root f-main-parent';
			if ( !empty($current_category) ) {
				$_current_category = get_term( $current_category, $category->taxonomy );
				if ( $category->term_id == $current_category )
					$class .=  ' active';
				elseif ( $category->term_id == $_current_category->parent )
					$class .=  ' active';
			}
			$output .=  ' class="' . $class . '"';
			$output .= ">$link\n";
		} else {
			$output .= "\t$link<br />\n";
		}
	}

	/**
	 * @see Walker::end_el()
	 * @since 2.1.0
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param object $page Not used.
	 * @param int $depth Depth of category. Not used.
	 * @param array $args Only uses 'list' for whether should append to output.
	 */
	function end_el(&$output, $page, $depth, $args) {
		if ( 'list' != $args['style'] )
			return;

		$output .= "</li>\n";
	}

}

	/*
		hilight search
	*/
	function hls_set_query() {
  $query  = attribute_escape(get_search_query());
 
  if(strlen($query) > 0){
    echo '
      <script type="text/javascript">
        var hls_query  = "'.$query.'";
      </script>
    ';
  }
}
 
function hls_init_jquery() {
  wp_enqueue_script('jquery');
}
add_action('init', 'hls_init_jquery');
add_action('wp_print_scripts', 'hls_set_query');


?>
